package com.webautotest.tests.common;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class ScreenShotUtil {
  public static ChromeDriver chromeDriver= CommonDriver.getChromeDriver();
   public static void getScreenShot(String className) throws IOException {
        List<String> times=getTimes();
        String fileName="./src/test/antotest-"+times.get(0)+"/"+className+"-"+times.get(1)+".png";
        File srcFile= chromeDriver.getScreenshotAs(OutputType.FILE);
        // 把屏幕截图放到指定路径下
        FileUtils.copyFile(srcFile,new File(fileName));
    }
      public static  List<String> getTimes(){
        SimpleDateFormat fileNameS=new SimpleDateFormat("yyyyMMdd-HHmmssSS");
        SimpleDateFormat dirNameS=new SimpleDateFormat("yyyy-MM-dd");
        String fileName=fileNameS.format(System.currentTimeMillis());
        String dirName=dirNameS.format(System.currentTimeMillis());
        List<String> list=new ArrayList<>();
        list.add(dirName);
        list.add(fileName);
        return list;
    }
}
